package main

import "fmt"

func producer(chnl chan int)  {
	for i := 0; i < 10; i++ {
		chnl <- i
	}
	close(chnl)
}

func main() {
	chnl := make(chan int)
	go producer(chnl)
	for {
		v, ok := <-chnl
		if ok == false {
			break
		}
		fmt.Println("received ", v, ok)
	}
	// 可以使用range直接遍历通道
	chnl = make(chan int)
	go producer(chnl)
	for v := range chnl {
		fmt.Println("range received ", v)
	}
}
